package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.Announcement;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.AnnouncementMapper;
import com.itheima.service.db.AnnouncementService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class AnnouncementServiceImpl implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize) {
        //封装分页对象
        IPage<Announcement> page = new Page(pageNum,pageSize);
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("created");
        page = announcementMapper.selectPage(page, queryWrapper);

        //查询公告具体信息
        List<Announcement> announcementList = announcementMapper.selectList(null);


        return new PageBeanVo(pageNum,pageSize,page.getTotal(),announcementList);
        //return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }
}
